package cn.edu.stu.syllabus.oa.list;

import cn.edu.stu.syllabus.api.OaInfoApi;
import cn.edu.stu.syllabus.dao.OaReadEntryDao;
import cn.edu.stu.syllabus.repository.oa.OaDataSource;
import cn.edu.stu.syllabus.repository.oa.OaSearchInfo;
import cn.edu.stu.syllabus.repository.oa.remote.OaRemoteDataSource;
import cn.edu.stu.syllabus.repository.oaRead.OaReadDataSource;
import cn.edu.stu.syllabus.repository.oaRead.local.OaReadLocalDataSource;
import cn.edu.stu.syllabus.di.qualifier.Local;
import cn.edu.stu.syllabus.di.qualifier.Remote;
import cn.edu.stu.syllabus.di.scope.FragmentScoped;
import cn.edu.stu.syllabus.utils.GreenDaoUtils;
import cn.edu.stu.syllabus.utils.OaRetrofit;
import dagger.Module;
import dagger.Provides;

/**
 * Created by daidaijie on 2017/3/14.
 */

@Module
public class OaPresenterModule {

    private final OaContract.View mView;
    private final OaSearchInfo mOaSearchInfo;

    public OaPresenterModule(OaContract.View view, OaSearchInfo oaSearchInfo) {
        mView = view;
        mOaSearchInfo = oaSearchInfo;
    }

    @FragmentScoped
    @Provides
    OaContract.View provideView() {
        return mView;
    }

    @FragmentScoped
    @Provides
    OaSearchInfo provideSearchInfo() {
        return mOaSearchInfo;
    }


    @FragmentScoped
    @Provides
    OaInfoApi provideOaInfoApi() {
        return OaRetrofit.getRetrofit().create(OaInfoApi.class);
    }

    @FragmentScoped
    @Provides
    @Remote
    OaDataSource provideOaRemoteDataSource(OaInfoApi oaInfoApi) {
        return new OaRemoteDataSource(oaInfoApi);
    }

    @FragmentScoped
    @Provides
    @Local
    OaReadDataSource provideOaReadLocalDataSource(OaReadEntryDao oaReadEntryDao) {
        return new OaReadLocalDataSource(oaReadEntryDao);
    }

    @FragmentScoped
    @Provides
    OaReadEntryDao proOaReadEntryDao() {
        return GreenDaoUtils.getInstance().getSession().getOaReadEntryDao();
    }

}
